<template>
  <!--已完成订单表格-->
  <!--页头-->
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>历史订单</el-breadcrumb-item>
    </el-breadcrumb>
    <order-list
        :order="order"
        @handleCurrentChange="handleCurrentChange"
        @handleSizeChange="handleSizeChange"
        @showComment="showComment"
    ></order-list>
  </div>
</template>

<script>
import OrderList from "../../components/OrderList";
export default {
  name: "CompletedOrder",
  components: {OrderList},
  data() {
    return {
      order: {
        orderMsg: [],
        queryInfo: {
          query: '',
          pagenum: 1,
          pagesize: 4
        },
        total: 0
      }
    }
  },
  created() {
    this.getOrderList();
  },
  methods: {
    getOrderList() {
      this.$axios({
        method: "get",
        url: "/order/completed",
        params: {
          rid: this.$store.getters.rid,
          query: this.order.queryInfo.query,
          pagenum: this.order.queryInfo.pagenum,
          pagesize: this.order.queryInfo.pagesize
        }
      })
          .then(response => {
            if (response.data.success) {
              this.order.orderMsg = response.data.completed_order_list;
              this.order.total = response.data.total;
              console.log(response.data.completed_order_list)
              if(response.data.completed_order_list.length===0){
                this.order.total=0;

              }
            }
          })
          .catch(error => console.log(error))
    },
    handleSizeChange(data) {
      this.queryInfo = data
      this.getOrderList()
    },
    //监听 页码值 改变事件
    handleCurrentChange(data) {
      this.queryInfo = data
      this.getOrderList()
    },
    //  查看此订单的评价
    showComment(id) {
      this.$axios({
        method: "get",
        url: "/order/mycomment",
        params: {
          id: id
        }
      }).then(response => {
        if (response.data.success) {
          this.$notify({
            title: response.data.rate + '星',
            message: response.data.content,
            duration: 0
          });
        }
        console.log(response.data.message);
      })
          .catch(error => console.log(error))
    }
  }
}
</script>

<style scoped>

</style>
